package com.persondemo.videoappliction.ui.video.presenter;

import android.util.Log;

import com.persondemo.videoappliction.bean.VideoBean;
import com.persondemo.videoappliction.net.BaseApi;
import com.persondemo.videoappliction.net.RxSchedulers;
import com.persondemo.videoappliction.ui.base.BaseContract;
import com.persondemo.videoappliction.ui.base.BasePresenter;
import com.persondemo.videoappliction.ui.video.contract.VideoDetilContract;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;

/**
 * Created by Administrator on 2018/3/27.
 */

public class VodeoPresenter extends BasePresenter<VideoDetilContract.View> implements VideoDetilContract.Presenter {
    BaseApi baseApi;
    @Inject
    public VodeoPresenter(BaseApi baseApi) {
        this.baseApi = baseApi;
    }

    @Override
    public void getdata(int id) {
        baseApi.getvideodata(id)
                .compose(RxSchedulers.<VideoBean>applySchedulers())
                .compose(mView.<VideoBean>bindToLife())
                .subscribe(new Observer<VideoBean>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                    }

                    @Override
                    public void onNext(@NonNull VideoBean videoBean) {
                        if (videoBean == null) {
                            mView.showFaild();
                            return;
                        } else {
                            mView.loaddata(videoBean);
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
